package org.ehe.erp.controller.quality;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.oss.entity.UploadResult;
import org.ehe.erp.domain.quality.vo.ErpQualityAttachmentVo;
import org.ehe.erp.service.quality.ErpQualityAttachmentService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 质检附件
 * @author :zhangnn
 * @className :ErpQualityAttachmentController
 * @description: TODO
 * @date 2025-09-10 16:41:35
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/quality/attachment")
public class ErpQualityAttachmentController extends BaseController {

    private final ErpQualityAttachmentService attachmentService;

    /**
     * 通用上传（返回路径）
     */
    //@SaCheckPermission("quality:attachment:add")
    @PostMapping("/upload")
    public R<UploadResult> upload(@RequestParam("file") MultipartFile file) {
        return R.ok(attachmentService.upload(file));
    }

    /**
     * 根据反馈ID查询附件列表
     */
    //@SaCheckPermission("quality:attachment:query")
    @GetMapping("/listByFeedback/{feedbackId}")
    public R<List<ErpQualityAttachmentVo>> listByFeedback(@PathVariable Long feedbackId) {
        return R.ok(attachmentService.listByFeedbackId(feedbackId));
    }

    /**
     * 删除附件（物理删）
     */
    //@SaCheckPermission("quality:attachment:remove")
    @Log(title = "质检附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(attachmentService.deleteWithValidByIds(List.of(ids)));
    }
}
